package com.gitee.minimalismstyle.fresh.sys.api.option

import com.gitee.minimalismstyle.fresh.common.core.domain.Simple
import com.gitee.minimalismstyle.fresh.common.core.option.Options
import com.gitee.minimalismstyle.fresh.sys.api.service.SysKeyValueService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
class KeyValueOptions : Options {

    @Autowired
    lateinit var sysKeyValueService: SysKeyValueService

    override fun get(param: Any): List<Simple> {
        return sysKeyValueService.findByParentKeyPath(param.toString()).get().map {
            val simple = Simple()
            simple["code"] = it.key
            simple["text"] = it.value
            simple["enabled"] = it.enabled
            simple
        }
    }
}